package com.lyl.servicebase.config;

import com.lyl.commonutils.R;
import com.lyl.exception.ZxjyException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public R error(Exception e){
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }

    @ExceptionHandler(ZxjyException.class)
    @ResponseBody
    public R error(ZxjyException e){
        e.printStackTrace();
        return R.error().message(e.getMessage());
    }
}
